﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace KwaiXiaoDian.OpenApi.Swagger
{
    /// <summary>
    /// swagger 过滤器
    /// </summary>
    /// <seealso cref="Swashbuckle.AspNetCore.SwaggerGen.IDocumentFilter" />
    public class SwaggerDocumentFilter : IDocumentFilter
    {
        public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
        {
           var dict = new OpenApiPaths();
            foreach (var item in swaggerDoc.Paths)
            {
                // 通过过滤器把 url 修改成小写的
                dict[item.Key.ToLower()] = item.Value;
            }            
            swaggerDoc.Paths = dict;
        }
    }
}
